package com.yenlien.traceyun.control.controller;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.control.entity.News;
import com.yenlien.traceyun.control.service.NewsService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 消息中心
 */
@RestController
@RequestMapping("/news")
public class NewsController extends BaseController {

    @Autowired
    private NewsService newsService;

    /**
     * 查询意见
     *
     * @param params
     * @return
     */
    @PostMapping("/inquire")
    public Object inquire(@RequestBody JSONObject params) {
        Integer page = params.getInteger("page");
        if (page > 0) {
            Integer page1 = page - 1;
            return buildPage(newsService.select(page1));
        } else {
            return fail("页面加载错误");
        }
    }

    @PostMapping("/add")
    public Object add(@RequestBody News news) {
        newsService.add(news);
        return success("成功");
    }


    @RequestMapping("/delete")
    public Object delete(@RequestParam("id") String id) {
        newsService.del(id);
        return success("成功");
    }


}
